package com.ruoyi.classperformance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.academic.domain.StudentAcademicInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.classperformance.domain.Classperformance;
import com.ruoyi.classperformance.service.IClassperformanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生课堂现记录Controller
 *
 * @author dongyv
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/classperformance/classperformance")
public class ClassperformanceController extends BaseController
{
    @Autowired
    private IClassperformanceService classperformanceService;

    /**
     * 查询学生课堂现记录列表
     */
    @PreAuthorize("@ss.hasPermi('classperformance:classperformance:list')")
    @GetMapping("/list")
    public TableDataInfo list(Classperformance classperformance)
    {

        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<Classperformance> list = classperformanceService.selectClassperformanceList(classperformance);
            return getDataTable(list);
        }
        else
        {
            //学生
            startPage();
            List<Classperformance> list = classperformanceService.selectClassperformanceList_student(teacherId);
            return getDataTable(list);
        }


    }

    /**
     * 导出学生课堂现记录列表
     */
    @PreAuthorize("@ss.hasPermi('classperformance:classperformance:export')")
    @Log(title = "学生课堂现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Classperformance classperformance)
    {
        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            List<Classperformance> list = classperformanceService.selectClassperformanceList(classperformance);
            ExcelUtil<Classperformance> util = new ExcelUtil<Classperformance>(Classperformance.class);
            util.exportExcel(response, list, "学生课堂现记录数据");
        }
        else
        {
            //学生
            List<Classperformance> list = classperformanceService.selectClassperformanceList_student(teacherId);
            ExcelUtil<Classperformance> util = new ExcelUtil<Classperformance>(Classperformance.class);
            util.exportExcel(response, list, "学生课堂现记录数据");
        }


    }

    /**
     * 获取学生课堂现记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('classperformance:classperformance:query')")
    @GetMapping(value = "/{performanceId}")
    public AjaxResult getInfo(@PathVariable("performanceId") Long performanceId)
    {
        return success(classperformanceService.selectClassperformanceByPerformanceId(performanceId));
    }

    /**
     * 新增学生课堂现记录
     */
    @PreAuthorize("@ss.hasPermi('classperformance:classperformance:add')")
    @Log(title = "学生课堂现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Classperformance classperformance)
    {
        return toAjax(classperformanceService.insertClassperformance(classperformance));
    }

    /**
     * 修改学生课堂现记录
     */
    @PreAuthorize("@ss.hasPermi('classperformance:classperformance:edit')")
    @Log(title = "学生课堂现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Classperformance classperformance)
    {
        return toAjax(classperformanceService.updateClassperformance(classperformance));
    }

    /**
     * 删除学生课堂现记录
     */
    @PreAuthorize("@ss.hasPermi('classperformance:classperformance:remove')")
    @Log(title = "学生课堂现记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{performanceIds}")
    public AjaxResult remove(@PathVariable Long[] performanceIds)
    {
        return toAjax(classperformanceService.deleteClassperformanceByPerformanceIds(performanceIds));
    }
}
